<?php
require_once ("../db/connectdatabase.php");
require_once ("../entitys/QuestionLoan.php");

function getQuestions() {
	$con = new ConnectDB();
	$tbl = "questionloans";
	$fn = array('question_id', 'loan_id', 'question', 'answer', 'dateupdate');
	$condetion = array('isuse' => true);
	return $con -> getvalueorderby($tbl, $fn, $condetion, 'dateupdate');
}

function getQuestionByID($idquestion) {
	$con = new ConnectDB();
	$tbl = "questionloans";
	$fn = array('question_id', 'loan_id', 'question', 'answer', 'dateupdate');
	$condetion = array('question_id' => $idquestion);
	return $con -> getvalueorderby($tbl, $fn, $condetion, 'dateupdate');
}

function getQuestionByLoan($idloan) {
	$con = new ConnectDB();
	$tbl = "questionloans";
	$fn = array('question_id', 'loan_id', 'question', 'answer', 'dateupdate');
	$condetion = array('loan_id' => $idloan);
	return $con -> getvalueorderby($tbl, $fn, $condetion, 'dateupdate');
}

function insertQuestion($question) {
	$con = new ConnectDB();
	$tbl = "questionloans";
	$fn = array('question_id' => ($question -> getID()), 'loan_id' => ($question -> getLoan()), 'question' => ($question -> getQuestion()), 'answer' => ($question -> getAnswer()), 'dateupdate' => ($question -> getDatecreate()));
	return $con -> insert($tbl, $fn);
}

function updateQuestion($question) {
	$con = new ConnectDB();
	$tbl = "questionloans";
	$fn = array('loan_id' => ($question -> getLoan()), 'question' => ($question -> getQuestion()), 'answer' => ($question -> getAnswer()), 'dateupdate' => ($question -> getDatecreate()));
	$condition = array('question_id' => ($question -> getID()));
	return $con -> update($tbl, $fn, $condition);
}

function deleteQuestion($idquestion) {
	$con = new ConnectDB();
	$tbl = "questionloans";
	$condition = array('question_id' => $idquestion);
	return $con -> delete($tbl, $condition);
}

?>